package com.example.management.controller;

import com.example.management.pojo.Building;
import com.example.management.response.Result;
import com.example.management.service.BuildingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "楼栋")
@RestController
@RequestMapping("/building")
public class BuildingController {
    @Autowired
    private BuildingService buildingService;

    @ApiOperation("所有楼栋信息")
    @PostMapping("getAll")
    public Result<List<Building>> getAllBuilding() {
        return Result.success(buildingService.getAllBuilding());
    }

    @ApiOperation("修改楼栋信息")
    @PostMapping("change")
    public String changeBuilding(@RequestParam Integer number, @RequestParam String tag,
                                 @RequestParam String position) {
        Building building = new Building(number, tag, position);
        return buildingService.changeBuilding(building);
    }

    @ApiOperation("删除指定楼栋")
    @PostMapping("delete")
    public String deleteBuilding(@RequestParam Integer number) {
        return buildingService.deleteBuilding(number);
    }

    @ApiOperation("添加新的楼栋")
    @PostMapping("add")
    public String addBuilding(@RequestParam Integer number, @RequestParam String tag, String position) {
        Building building = new Building(number, tag, position);
        return buildingService.addBuilding(building);
    }
}
